package cn.com.bluemoon.daps.api.standard.factory;

import cn.com.bluemoon.daps.api.standard.RemoteStandardIndexService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.standard.entity.DapStandardIndex;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 标准服务降级处理
 *
 * @author Jarod Kong
 */
@Component
public class RemoteStandardIndexFallbackFactory implements FallbackFactory<RemoteStandardIndexService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteStandardIndexFallbackFactory.class);

    @Override
    public RemoteStandardIndexService create(Throwable throwable) {
        log.error("数据标准-指标调用失败:{}", throwable.getMessage());
        return new RemoteStandardIndexService() {


            @Override
            public ResultBean<DapStandardIndex> getById(String id) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiStandard.PROD_SERVICE, "第三方服务调用-获取标准指标失败");
            }

            @Override
            public ResultBean<Boolean> relatedBizLineId(Integer bizLineId) {
                return ResultBean.ok(false);
            }
        };
    }
}
